package com.huazhi.wzsnw.util.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * @author zhengch
 * @date 2022年05月23日 2:33 下午
 * redis 存储过期时回调
 */
@Configuration
public class RedisListenerConfig {
    @Autowired
    private RedisConnectionFactory redisConnectionFactory;

    @Bean
   public   RedisMessageListenerContainer container(){
        RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
        redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory);
        return redisMessageListenerContainer;
    }

    @Bean

   public  KeyExpiredListener keyExpiredListener(){

        return  new KeyExpiredListener(this.container());
    }


}
